// pages/topicality/ruxue/ruxue.js
//获取应用实例
const app = getApp()
const util = require("../../../utils/util.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        stageIndex: 0,
        stagetitle: ["准备阶段", "报名阶段", "录取阶段"],
        showtk: false, // 跳转外链的弹框显示
        showNav: true, // 快捷导航是否展开
        isMore: true,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData({
            type: options.type ? options.type : '',
            citycode: options.city ? options.city : (wx.getStorageSync("citycode") ? wx.getStorageSync("citycode") : 'sz'),
        })
        util.getUrl(app.globalData.url).then((res) => {
            // 获取城市公众号二维码
            util.cityConfig(this.data.citycode).then(res => {
                this.setData({
                    qrcodeimg: res.qrcode,
                })
            })
            this.getruxueData()
        })

        // 获取屏幕高度
        wx.getSystemInfo({
            success: (res) => {
                var clientHeight = res.windowHeight,
                    clientWidth = res.windowWidth,
                    rpxR = 750 / clientWidth;
                var calc = clientHeight * rpxR;
                this.setData({
                    winHeight: calc
                });
            }
        });
    },

    // 入学接口
    getruxueData() {
        let data = {
            action: "ruxue",
            type: this.data.type,
            citycode: this.data.citycode,
        };
        util.request('zhuanti.php', data, ).then(res => {
            let ruxueData = res.data.data;
            let stageData = [{
                name: "准备阶段",
                data: {
                    desc: ruxueData.peizhi[0].zhunbei_desc,
                    linkIcon: ruxueData.zhunbei,
                    zixun: ruxueData.zhunbei_zixun,
                },
                isMore: true,
            }, {
                name: "报名阶段",
                data: {
                    desc: ruxueData.peizhi[0].baoming_desc,
                    linkIcon: ruxueData.baoming,
                    zixun: ruxueData.baoming_zixun,
                },
                isMore: true,
            }, {
                name: "录取阶段",
                data: {
                    desc: ruxueData.peizhi[0].luqu_desc,
                    linkIcon: ruxueData.luqu,
                    zixun: ruxueData.luqu_zixun,
                },
                isMore: true,
            }];
            this.setData({
                ruxueData,
                stageData
            })
            wx.setNavigationBarTitle({
                title: ruxueData.peizhi[0].cityname + ruxueData.peizhi[0].level,
            })
        })
    },

    // banner点击事件
    bannerClick(e) {
        let url = e.currentTarget.dataset.url;
        let linkname = e.currentTarget.dataset.title;
        let appid = e.currentTarget.dataset.appid;
        if (url.indexOf("pages") == -1 && url.indexOf("mp.weixin.qq.com") == -1) {
            this.setData({
                showtk: true
            })
            util.navContact(linkname, url)
        } else {
            util.navMethod(url, appid);
        }
    },

    // 必要助手点击事件
    aideClick(e) {
        let url = e.currentTarget.dataset.url;
        let linkname = e.currentTarget.dataset.title;
        if (url.indexOf("pages") == -1 && url.indexOf("mp.weixin.qq.com") == -1) {
            this.setData({
                showtk: true
            })
            util.navContact(linkname, url)
        } else {
            util.navMethod(url);
        }
    },



    // 阶段点击事件
    stageClick(e) {
        let stageIndex = e.currentTarget.dataset.index;
        this.setData({
            stageIndex,
        })
    },

    swcontent: function(e) {
        var currentid = e.detail.current;
        this.setData({
            stageIndex: currentid,
        })
    },

    // 阶段icon点击事件
    iconClick(e) {
        let url = e.currentTarget.dataset.url;
        let linkname = e.currentTarget.dataset.title;
        let id = e.currentTarget.dataset.id;
        let type = e.currentTarget.dataset.type;
        if (id != 0) {
            wx.navigateTo({
                url: '/pages/article/detail/detail?id=' + id + '&type=' + type + '&city=' + this.data.citycode,
            })
        } else {
            if (url.indexOf("pages") == -1 && url.indexOf("mp.weixin.qq.com") == -1) {
                this.setData({
                    showtk: true
                })
                util.navContact(linkname, url)
            } else {
                util.navMethod(url);
            }
        }

    },

    // 查看更多
    seemore(e) {
        let name = e.currentTarget.dataset.name;
        this.data.stageData.forEach((v, k) => {
            if (name == v.name) {
                this.data.stageData[k].isMore = false;
            }
        })
        this.setData({
            // isMore: false,
            stageData: this.data.stageData
        })
    },

    // 进入客服会话
    contact() {
        this.setData({
            showtk: false,
        })
    },

    // 关闭
    close() {
        this.setData({
            showtk: false,
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
        return {
            title: "本地宝-积分入学",
            imageUrl: "http://imgbdb3.bendibao.com/xcxbdb/file/20212/9/20210209161843_68677.jpg"
        }
    },

    // 分享朋友圈
    onShareTimeline: function() {
        return {
            title: "本地宝-积分入学",
            imageUrl: "http://imgbdb3.bendibao.com/xcxbdb/file/20212/9/20210209161843_68677.jpg",
            query: { type: this.data.type, city: this.data.citycode },
        }
    },

    /**
     * 页面滑动事件的处理函数
     */
    onPageScroll: function(e) {
        this.setData({
            showNav: false,
            scrollTop: e.scrollTop,
        })
    }
})